package com.aistar.controller;

import com.aistar.pojo.ClubActivity;
import com.aistar.pojo.Member;
import com.aistar.service.ClubdetailsService;
import com.aistar.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/club_details")
public class ClubdetailsController {

    @Autowired
    private ClubdetailsService clubdetailsService;
    @Autowired
    private MemberService memberService;
    //报名用户渲染
    @RequestMapping("/list/{id}")
    public ModelAndView list2(HttpServletRequest request,Model model,@PathVariable("id") int clubId){


        ClubActivity clubActivity = clubdetailsService.selectByPrimaryKey(clubId);
        Integer count = clubdetailsService.selectCount(clubId);
        model.addAttribute("clubdetails",clubActivity);
        model.addAttribute("Count",count);
        model.addAttribute("picture",clubActivity.getClubOther1());

        //club_id

        Object ss = request.getSession().getAttribute("userId");//获得session里的用户id
        int userId = Integer.parseInt(String.valueOf(ss));
        Member memberaa = memberService.getbyId(userId);


        List<Integer> integerList = clubdetailsService.selectByClubId(clubId);
        System.out.println("生成集合 = " + integerList);
        List<Member> memberList = new ArrayList<>();
        for(Integer integer:integerList){
            Member member= clubdetailsService.selectByUserId(integer);
            memberList.add(member);
        };
        System.out.println("查询出的用户集合：" + memberList);
        ModelAndView mav = new ModelAndView();
        mav.addObject("memberList", memberList);
        mav.setViewName("ClubList/club_details");
        mav.addObject("memberall",memberaa);
        return mav;
    }
}
